﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using BLLA;
using Common;
using LoveEat.Helper;
namespace LoveEat.WebController
{
    public class HomeController : BaseController
    {



        [Route("do/{wechatInfoId}}")]
        public ActionResult DoActivityLaunch(int wechatInfoId)
        {
            var wechatInfo =OperateContext.Current.BLLSession.Iwechat_infoBLL.GetListBy(s => s.id == wechatInfoId).FirstOrDefault();
            if (wechatInfo == null || wechatInfo.id <= 0)
            {
                Log.Error("CloudCardController | DoActivityLaunch | invalid draw qr code: " + wechatInfoId);
                return RedirectToAction("ErrorHappened", "GoodLuckway");
            }
            var strCallBackUrl = "http://" + Request.Url.Host + "/Home/ActivityLaunch?wechatInfoId=" + wechatInfo.id;//默认进来扫描页面

            var strAuthInterfaceUrl = ConfigurationManager.AppSettings["LuckMpAuthInterfaceUrl"] + "?wechatInfoId=" +
                                      wechatInfo.id + "&callBackUrlEncode=" +
                                      System.Web.HttpContext.Current.Server.UrlEncode(strCallBackUrl);
            Response.Redirect(strAuthInterfaceUrl);
            return View();
        }

        public ActionResult ActivityLaunch(int wechatInfoId, string openId)
        {

            var wechat_user = OperateContext.Current.BLLSession.Iwechat_userBLL.GetListBy(s => s.OpenId == openId).FirstOrDefault();
            ViewBag.Headimgurl = wechat_user.Headimgurl;
            ViewBag.NickName = wechat_user.NickName;
            return View();
        }

        public ActionResult test()
        {

            var wechatInfo = OperateContext.Current.BLLSession.Iwechat_infoBLL.GetListBy(w => w.originalId == "aichidiancan").FirstOrDefault();

            if (wechatInfo == null || wechatInfo.id <= 0)
            {
                Log.Info("LuckyMpController | ReceiveWxEventPost None WechatMp Info - " + wechatInfo);
                return View();
            }
            return View();
        }
        public ActionResult Index()
        {

            IBLL.IemployeeBLL ss = new BLLA.employee();


            var sss = OperateContext.Current.BLLSession.IemployeeBLL.GetListBy(s => s.employee_id > 0);

            return View();
        }
    }
}
